<template>
	<view >
		<view class="flex align-c nav" :style="{paddingTop: statusBar + 'px'}">
			<image src="/static/home/back.png" mode="widthFix" class="nav_back_icon" @click="$back" />
			<view class="f1">
				<view class="nav_seach_box flex align-c">
					<image src="/static/home/seach-icon-gray.png" mode="aspectFill" class="nav_seach_icon" />
					<input type="text" class="input-box" v-model="keyword" placeholder="搜索课程" placeholder-class="p-c">
				</view>
			</view>
			<view class="flex align-c nav_right" @click="open">
				<image src="/static/home/sort-icon.png" mode="aspectFill" class="nav_sort-icon" />
				<view v-if="type">{{ `${typeList[typeIndex].name}类型` }}</view>
				<view v-else>请选择</view>
			</view>
		</view>
		
		<scroll-view scroll-x="true" class="flex align-c tabs" :style="{top: statusBar+ 44 + 'px'}">
			<view class="tabs_item" v-for="(v,i) in navdatas" :key="i" @click="checkNav(v.id)">
				<view class="item-name" :class="{'act': class_id == v.id}" >{{ v.name }}</view>
				<view class="tabs_line" :class="{'tabs_line_act': class_id == v.id}"></view>
			</view>
		</scroll-view>
		
		<view :style="{height: statusBar + 88 +'px'}" />
		
		<view class="course" v-for="(v,i) in list" :key="i">
			<view class="course_content flex" @click="$to(`/pages/home/overt/course_detail`)">
				<image v-if="v && v.course && v.course.cover" :src="$img(v.course.cover)" mode="aspectFill" class="course_content_img" />
				<image v-else src="/static/home/upload_img.png" mode="aspectFill" class="course_content_img" />
				<view class="f1 between column">
					<view class="">
						<view class="fw-b" v-if="v && v.course && v.course.title">{{ v.course.title }}</view>
						<view class="fw-b" v-else>修炼性感美背</view>
						<view class="course_content_label" v-if="v && v.course && v.course.start_at">时间：{{ v.course.start_at }}</view>
						<view class="course_content_label" v-else>时间：2022-12-07 14:30</view>
					</view>
					<view class="course_content_price">
						<text class="symbol">￥</text>
						<text class="fw-b">399</text>
						<text class="util">/节</text>
					</view>
				</view>
			</view>
			<view class="course_bottom flex align-c" >
				<view class="flex align-c">
					<image src="/static/home/del-icon-gray.png" mode="widthFix" class="del-icon-gray" />
					<view class="gray">删除</view>
				</view>
				<view class="f1 flex align-c course_bottom_box">
					<button class="btn org_btn" @click="backMoney(v.id)">上架</button>
					<button class="btn" @click="woffrecord(v.id)">编辑</button>
				</view>
			</view>
		</view>
		
		<u-popup :show="show" :round="10" mode="bottom" @close="close" @open="open">
			<view class="item_box">
				<view class="item" v-for="(item,index) in typeList" :key="index" @click="checkType(index)">{{ item.name }}</view>
				<view class="item_red" @click="close">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBar: 0,
				keyword: '',
				navdatas: [],
				status: 1,
				list: [],
				show: false,
				type: 1,
				typeIndex: 0,
				typeList: [
					{
						name: '按上架',
						type: 1,
					},
					{
						name: '按下架',
						type: 2,
					},
				],
				shop_id: '',
				class_id: '',
				last_page: 1,
				page: 1,
			}
		},
		onLoad(opt) {
			if(opt&& opt.type) {
				this.status = parseInt(opt.type)
			}
			this.getSystemInfo();
			this.shop_id = uni.getStorageSync('shopId');
		},
		onShow() {
			this.getClass();
		},
		methods: {
			getSystemInfo() {
				uni.getSystemInfo({
					success: (e) => {
						this.statusBar = e.statusBarHeight
					}
				})
			},
			checkNav(i){
				this.class_id = i;
				this.getCourseList();
			},
			async getClass() {
				let res = await this.$api.get('staff/course/class',);
				if(res.code == 200) {
					this.navdatas = res.data;
					this.class_id = res.data[0].id;
					this.getCourseList();
				}
			},
			async getCourseList() {
				let res = await this.$api.get('staff/course/list',{
					type: 2,
					shop_id: this.shop_id,
					class: this.class_id,
					status: this.status,
					key: this.keyword,
					page: this.page,
				});
				if(res.code == 200) {
					this.list = res.data.data;
					this.last_page = parseInt(res.data.to)/parseInt(res.data.per_page);
				}
			},
			open() {
				this.show = true;
			},
			close() {
				this.show = false;
			},
			checkType(i) {
				this.typeIndex = i;
				this.status = this.typeList[i].type;
				this.show = false;
				this.getCourseList();
			},
			backMoney(id){
				this.$to(`/pages/refund/refund?id=${id}`)
			},
			woffrecord(id){
				this.$to(`/pages/home/write-off_record?id=${id}`)
			},
			toDetail(id){
				this.$to(`/pages/home/course_detail?id=${id}`)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.nav {
		font-size: 24rpx;
		background-color: #FFF;
		height: 44px;
		line-height: 44px;
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		z-index: 999;
		&_back_icon {
			width: 15rpx;
			height: 27rpx;
			margin-left: 27rpx;
			margin-right: 20rpx;
		}
		&_seach_box {
			background-color: #F5F5F5;
			border-radius: 30rpx;
			padding: 12rpx 36rpx;
			margin: 0 27rpx;
			margin-left: 20rpx;
		}
		.input-box {
			font-size: 27rpx;
			flex: 1;
			margin: 0 20rpx;
		}
		&_seach_icon {
			width: 25rpx;
			height: 25rpx;
		}
		&_sort-icon {
			width: 29rpx;
			height: 29rpx;
			margin-right: 10rpx;
		}
		&_filter {
			width: 29rpx;
			height: 29rpx;
			margin-right: 10rpx;
			margin-left: 80rpx;
		}
		&__class__type {
			justify-content: flex-end;
			margin-right: 20rpx;
		}
		&_right {
			margin-right: 27rpx;
		}
	}

	.tabs {
		background-color: #FFF;
		height: 44px;
		line-height: 44px;
		padding-left: 40rpx;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 999;
		white-space: nowrap;
		&_item {
			display: inline-block;
			font-size: 27rpx;
			color: #B3B3B3;
			margin-right: 72rpx;
		}
		.item-name {
			line-height: 54rpx;
		}
		.act {
			color: #F17816;
		}
		&_line {
			height: 7rpx;
			background: #ffffff;
			width: 53rpx;
			bottom: 2px;
			border-radius: 100px;
			transition-property: transform;
			transition-duration: 300ms;
			margin: 0 auto;
		}
		&_line_act {
			background-color: #F17816;
		}
	}
	
	.course {
		font-size: 27rpx;
		padding: 0 20rpx;
		background-color: #fff;
		margin: 20rpx 27rpx;
		border-radius: 20rpx;
		&_content {
			padding: 20rpx 0;
			font-size: 29rpx;
			&_img {
				width: 160rpx;
				height: 160rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
			}
			&_label {
				font-size: 27rpx;
				color: #B3B3B3;
				margin-top: 10rpx;
			}
			&_price {
				color: #F51818;
				text-align: right;
				.symbol {
					font-size: 27rpx;
				}
				.fw-b {
					font-family: PingFang SC Bold;
					font-size: 32rpx;
				}
				.util {
					font-size: 24rpx;
				}
			}
		}
		&_bottom {
			padding-top: 10rpx;
			padding-bottom: 30rpx;
			justify-content: flex-end;
			font-size: 24rpx;
			.btn {
				margin: 0;
				padding: 0;
				padding: 0 24rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				height: 47rpx;
				line-height: 47rpx;
				min-width: 93rpx;
				text-align: center;
				margin-left: 24rpx;
				background-color: #FFF;
				min-width: 120rpx;
			}
			.org_btn {
				background-color: #F17816;
				color: #fff;
			}
			.del-icon-gray {
				width: 23rpx;
				height: 23rpx;
				margin-right: 8rpx;
			}
			&_box {
				justify-content: flex-end;
			}
		}
	}
	
	.item_box {
		background-color: #F5F5F5;
		border-radius: 20rpx 20rpx 0 0;
		overflow: hidden;
		.item,.item_red {
			height: 98rpx;
			line-height: 98rpx;
			text-align: center;
			font-size: 32rpx;
			background-color: #FFF;
			border-bottom: 2rpx solid #F5F5F5;
		}
		.item_red {
			color: #F11A1A;
			margin-top: 20rpx;
		}
		.item:last-child {
			border-bottom: none;
		}
	}
</style>